<!DOCTYPE html>
<html>
<head>
	<title></title>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/list.css">
</head>
<body>
<div class="list">
	<!-- Container -->
	<div id="container">
		<div class="shell">
			<!-- Main -->
			<div id="main">
				<div class="cl">&nbsp;</div>
				
				<!-- Content -->
				<div id="content">
					
					<!-- Box -->
					<div class="box menu">
						<!-- Box Head -->
						<div class="box-head">
							<h2 class="left">管理员信息数据</h2>
						</div>
						<!-- End Box Head -->	

						<!-- Table -->
						<div class="table">
							<table width="100%" border="0" cellspacing="0" cellpadding="0">
								<tr>
									<th width="13"><input type="checkbox" class="checkbox" /></th>
									<th>管理员</th>
									<th class="response">管理员信息</th>
									<th>操作</th>
								</tr>
								<foreach name="list" item="vo">
									<tr class="row">
										<td><input type="checkbox" class="checkbox" /></td>
										<td><h3><a href="#">{$vo['username']}</a></h3></td>
										<td class="res"><p>{$vo['intro']}</p></td>
										<td>
											<a href="###" class="ico del"  onclick="if(confirm('确定删除吗 ?')){deletes({$vo['id']},this)}">删除</a><a href="###" class="ico edit" _username="{$vo['username']}"
											_password="{$vo['password']}" _intro="{$vo['intro']}"
											 _id="{$vo['id']}">编辑</a>
										</td>
									</tr>
								</foreach>
							</table>				
							<!-- Pagging -->
							<div class="pagging">
								<div class="left"><a href="###">添加</a><span class="reminder">{$reminder}</span></div>
								<div class="right">{$page}
								</div>
							</div>
							<!-- End Pagging -->
						</div>
						<!-- Table -->
						
					</div>
					<!-- End Box -->
					<div class="box edit-1">
						<!-- Box Head -->
						<div class="box-head">
							<h2 class="left">编辑管理员信息</h2>
						</div>
						<!-- End Box Head -->
						<div class="syrian-main-page">
                            <div class="form-group-1">
                                <span class="col-sm-1">账号:</span><span class="adminaccount"></span>
                            </div>
                            <div class="form-group-1">
                                <span class="col-sm-1">密码:</span><input type="password" class="reply-control password" placeholder="请输入密码"  name="password">
                                <span class="reminder-2 reminder"></span>
                            </div>
                            <div class="form-group-1">
                                <span class="col-sm-1">确认密码:</span><input type="password" class=" reply-repswd repassword" placeholder="请再次输入密码"  name="repassword">
                                <span class="reminder-3 reminder"></span>
                            </div>
                            <div class="form-group-2">
                                <span class="col-sm-11">管理员信息:</span>
                                <textarea class="response-control edit-control intro" 
                                name="intro" _id="" placeholder="请输入简介"></textarea>
                                <span class="reminder-4 reminder"></span>
                       	 	</div>
                            <div class="col-sm-11">
                               <button type="button" class="btn edit-submit tj-button">提交</button>
                               <button type="button" class="btn btn-cancel">取消</button>
                            </div>
						</div>
					<!-- End Box -->
					</div>
					<div class="box add">
						<!-- Box Head -->
						<div class="box-head">
							<h2 class="left">添加管理员</h2>
						</div>
						<!-- End Box Head -->
						<div class="syrian-main-page">
	                        <form action="{:U('user/inserts')}" method="post">
	                            <div class="form-group-1">
	                                <span class="col-sm-1">账号:</span><input type="text" class="reply-control username" placeholder="请输入账号"  name="username">
	                                <span class="reminder-1 reminder"></span>
	                            </div>
	                            <div class="form-group-1">
	                                <span class="col-sm-1">密码:</span><input type="password" class="reply-control password" placeholder="请输入密码"  name="password">
	                                <span class="reminder-2 reminder"></span>
	                            </div>
	                            <div class="form-group-1">
	                                <span class="col-sm-1">确认密码:</span><input type="password" class=" reply-repswd repassword" placeholder="请再次输入密码"  name="repassword">
	                                <span class="reminder-3 reminder"></span>
	                            </div>
                                <div class="form-group-2">
	                                <span class="col-sm-11">管理员信息:</span>
	                                <textarea class="response-control edit-control intro" name="intro" _id="" placeholder="请输入简介"></textarea>
	                                <span class="reminder-4 reminder"></span>
                           	 	</div>
	                            <div class="col-sm-11">
	                               <button type="submit" class="btn btn-submit tj-button">提交</button>
	                               <button type="button" class="btn btn-cancel">取消</button>
	                            </div>
							</form>
						</div>
					<!-- End Box -->
					</div>

				<!-- End Content -->
				</div>
				<div class="cl">&nbsp;</div>			
			</div>
			<!-- Main -->
		</div>
	</div>
	<!-- End Container -->
</div>
<script type="text/javascript" src="__PUBLIC__/js/jquery.js"></script>
<script type="text/javascript">
	function deletes(id,that){
		$.ajax({
			type:"post",
			async:true,
			url: "{:U('user/deletes')}",
			data:{id:id},
		    success: function(){
			 	$(that).parents('.row').remove();
			}
		});
	}


function reminder(){
	var oSubmit     = $('.add .btn-submit');
	var oUsername   = $('.add input.username');
	var oPassword   = $('.add input.password');
	var oRepassword = $('.add input.repassword');
	var oIntro      = $('.add textarea.intro');
	var oReminder1  = $('.add span.reminder-1');
	var oReminder2  = $('.add span.reminder-2');
	var oReminder3  = $('.add span.reminder-3');
	var oReminder4  = $('.add span.reminder-4');
	var regUsername = /^[A-Za-z0-9]{3,10}$/i;
	var regPassword = /^[A-Za-z0-9]{6,16}$/i;

	$(oSubmit).bind('click',function(){
		
		if( $(oUsername).val() == '' ){
			$(oReminder1).html('用户名不能为空');
			return false;
		} else if( ($(oUsername).val()).match(regUsername) == null ){
			$(oReminder1).html('用户名格式有误');
			return false;
		} else if($(oPassword).val() == ''){
			$(oReminder2).html('密码不能为空');	
			return false;
		} else if( ($(oPassword).val()).match(regPassword) == null ){
			$(oReminder2).html('密码格式有误');
			return false;
		} else if( $(oPassword).val() != $(oRepassword).val()){
			$(oReminder3).html('密码输入不一致');	
			return false;
		} else if( $(oIntro).val() == "" ){
			$(oReminder4).html('简介不能为空');	
			return false;
		} else{
			return true;
		}

	});
}
	reminder();

	function edit(){

		var aEdit         = $(".table .edit");
		var oUsername     = $(".edit-1 input.username");
		var oPassword     = $(".edit-1 input.password");
		var oRepassword   = $(".edit-1 input.repassword");
		var oIntro        = $(".edit-1 textarea.intro");
		var oAdminAccount = $(".edit-1 .adminaccount");
		var oList         = $("#container #content div.menu");
		var oUpdate       = $("#content .edit-1");
		var oSubmit       = $("#content .edit-submit");
		var oReminder2    = $('.edit-1 span.reminder-2');
		var oReminder3    = $('.edit-1 span.reminder-3');
		var oReminder4    = $('.edit-1 span.reminder-4');
		var regUsername = /^[A-Za-z0-9]{3,10}$/i;
		var regPassword = /^[A-Za-z0-9]{6,16}$/i;
		
		for( i = 0; i <= aEdit.length; i++ ){
			(function(i){
				$(aEdit[i]).bind('click',function(){
					var uId  = $(this).attr("_id");

					$(oList).fadeOut('normal');
					$(oUpdate).fadeIn(1500);
					
					$(oIntro).attr("_id", uId);
					
					var uUsername   = $(this).attr('_username');

					$(oAdminAccount).html(uUsername);
				});
			})(i);
		}
		
		$(oSubmit).bind('click',function(){	

		   if($(oPassword).val() == ''){
				$(oReminder2).html('密码不能为空');	
			} else if( ($(oPassword).val()).match(regPassword) == null ){
				$(oReminder2).html('密码格式有误');
			} else if( $(oPassword).val() != $(oRepassword).val()){
				$(oReminder3).html('密码输入不一致');	
			} else if( $(oIntro).val() == "" ){
				$(oReminder4).html('简介不能为空');	
			} else{
				// console.log($(oIntro).val());return;
				if(confirm('确定要修改吗？')){
					var aPassword     = $(oPassword).val();
					var aIntro        = $(oIntro).val();
					var aUsername     = $(oAdminAccount).html();
					var aId           = $(oIntro).attr("_id");

					$.ajax({
						type:"post",
						url: "{:U('User/renewal')}",
						data:{id:aId, username:aUsername, password:aPassword, intro:aIntro},
						success:function(){
							location.href = "";
						}
					});
				}
			}
		});
	};	
	edit();
</script>
<script type="text/javascript" src="__PUBLIC__/js/index.js"></script>
</body>
</html>